package com.danco.training.zaneuskaya.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.springframework.beans.factory.annotation.Required;

/**
 * @author Zaneuskaya Aliaksandra
 *
 */
@Entity
@Table(name = "account")
public class Account implements Serializable {

	/**
	 * 
	 * 
	 */
	private static final long serialVersionUID = -7119227132347050224L;

	@Id
	@Column(name = "account_id")
	@GeneratedValue
	private Integer accountId;

	@Column(name = "email", unique = true)
	private String email;

	@Column(name = "password")
	private String password;

	@Column(name = "role")
	@Enumerated(EnumType.STRING)
	private Role accountRole;

	public Integer getAccountId() {
		return accountId;
	}

	public void setAccountId(Integer accountId) {
		this.accountId = accountId;
	}

	public String getEmail() {
		return email;
	}

	@Required
	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	@Required
	public void setPassword(String password) {
		this.password = password;
	}

	public Role getAccountRole() {
		return accountRole;
	}

	public void setAccountRole(Role accountRole) {
		this.accountRole = accountRole;
	}

	public boolean isAdmin() {
		return Role.ADMIN.equals(accountRole);
	}

	public boolean isUser() {
		return Role.USER.equals(accountRole);
	}

	@Override
	public int hashCode() {
		return getAccountId();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Account) {
			Account other = (Account) obj;
			return other.getAccountId() == accountId;
		}
		return false;
	}

}
